package com.one.rope.mvp.web.controller.admin;

import com.one.rope.mvp.basecore.annotation.LogMethod;
import com.one.rope.mvp.web.business.service.IMemberInfoService;
import com.one.rope.mvp.web.common.dto.admin.member.*;
import com.one.rope.mvp.basecore.bean.ResponseObject;
import com.one.rope.mvp.web.common.util.ObjectUtils;
import com.one.rope.mvp.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author Weijian.Liu
 * @desc 后台管理端-会员用户控制器
 * @date 2020/2/20 16:16
 */
@Api(tags = "A3管理后台-会员用户模块")
@RestController
@RequestMapping(value = "/admin/api")
@Slf4j
public class AdminMemberInfoController extends BaseController {

  @Autowired
  IMemberInfoService memberInfoService;

  @LogMethod
  @ApiOperation(value = "001会员用户列表", notes = "会员用户列表接口", response = AdminMemberInfoListItemVO.class)
  @PostMapping(value = "/member/memberInfoList")
  public ResponseObject memberInfoList(@RequestBody AdminMemberInfoListDTO requestDTO) {
    try {
      return memberInfoService.memberInfoList(requestDTO);
    } catch (Exception e) {
      log.error("/admin/api/member/memberInfoList接口异常", e);
      return ResponseObject.systemError(e);
    }
  }

  @LogMethod
  @ApiOperation(value = "002编辑用户数据", notes = "编辑人才数据接口")
  @PostMapping(value = "/member/editMemberInfo")
  public ResponseObject editMemberInfo(@RequestBody AdminEditMemberInfoDTO requestDTO) {
    ObjectUtils.requestNonEmpty(requestDTO.getName(), "姓名不能为空");
    ObjectUtils.requestNonNull(requestDTO.getSex(), "称谓不能为空");
    try {
      return memberInfoService.editMemberInfo(requestDTO);
    } catch (Exception e) {
      log.error("/admin/api/member/editMemberInfo接口异常", e);
      return ResponseObject.systemError(e);
    }
  }

  @LogMethod
  @ApiOperation(value = "003会员用户列表-下拉框", notes = "会员用户列表接口", response = AdminMemberListVO.class)
  @PostMapping(value = "/member/memberList")
  public ResponseObject memberList(@RequestBody AdminMemberListDTO requestDTO) {
    try {
      return memberInfoService.memberList(requestDTO);
    } catch (Exception e) {
      log.error("/admin/api/member/memberList接口异常", e);
      return ResponseObject.systemError(e);
    }
  }

  @LogMethod
  @ApiOperation(value = "004人才数据列表", notes = "人才数据列表接口", response = AdminPersonInfoListItemVO.class)
  @PostMapping(value = "/member/personInfoList")
  public ResponseObject personInfoList(@RequestBody AdminPersonInfoListDTO requestDTO) {
    try {
      return memberInfoService.personInfoList(requestDTO);
    } catch (Exception e) {
      log.error("/admin/api/member/personInfoList接口异常", e);
      return ResponseObject.systemError(e);
    }
  }

  @LogMethod
  @ApiOperation(value = "005编辑人才数据", notes = "编辑人才数据接口")
  @PostMapping(value = "/member/editPersonInfo")
  public ResponseObject editPersonInfo(@RequestBody AdminEditPersonInfoDTO requestDTO) {
    ObjectUtils.requestNonEmpty(requestDTO.getName(), "姓名不能为空");
    ObjectUtils.requestNonEmpty(requestDTO.getMobile(), "手机号不能为空");
    ObjectUtils.requestNonNull(requestDTO.getSex(), "称谓不能为空");
    try {
      return memberInfoService.editPersonInfo(requestDTO);
    } catch (Exception e) {
      log.error("/admin/api/member/editPersonInfo接口异常", e);
      return ResponseObject.systemError(e);
    }
  }

  @LogMethod
  @ApiOperation(value = "006删除人才数据", notes = "删除人才数据接口")
  @GetMapping(value = "/member/deletePersonInfo/{id}")
  public ResponseObject deletePersonInfo(@PathVariable("id") Long id) {
    try {
      return memberInfoService.deletePersonInfo(id);
    } catch (Exception e) {
      log.error("/admin/api/member/deletePersonInfo接口异常", e);
      return ResponseObject.systemError(e);
    }
  }
}
